Binary tree with override nodes for representing a time-varying function in an enterprise model

ABSTRACT

A method of using a binary tree data structure to represent a time-varying variable, and to solve queries about the variable. The tree is especially useful for solving “find” type queries, such as “What is the earliest/latest time when a minimum of y units are on hand?” The binary tree is comprised of delta nodes that store delta values, that is, changes in the value of the variable. A delta value may be an “override” value, which represents a predetermined change in value of the function, such as a capacity value of a resource that is periodically replenished.

RELATED APPLICATIONS

This application is a continuation-in-part application of application Ser. No. 09/371,821 filed Aug. 11, 1999, entitled, Data Structure and Operations for Time-Varying Variable in an Enterprise Model.

TECHNICAL FIELD OF THE INVENTION

This invention relates to computer data structures and algorithms, and more particularly to a binary tree data structure for representing a time-varying function and to algorithms that use the data structure, for applications related to enterprise modeling.

BACKGROUND OF THE INVENTION

As applications for computer software get increasingly complex and sophisticated, so does the need for efficiency in performance of the software. An example of complex software is the “enterprise” software being used to model the operation of businesses, such as manufacturers or service providers. The enterprise model often includes time-varying quantities, such as inventory.

The enterprise model often includes scheduling type processes, where a need exists for performing queries about time-varying quantities. Sometimes the query might be a simple “function value” type of query, such as, “How many on hand at time t?”. However, a more practical “find” type of query asks for earliest/latest or maximum/minimum information. For example, a query seeking both “earliest” time and “minimum” amount information might ask, “Find the earliest time greater than t at which we will have a minimum of n units of material on hand?”, where t is the earliest time at which a task might be scheduled (due to other constraints) and n is the number of units of material that the task will consume.

One approach to solving queries involving time-varying variables is to represent values of the variable with a “binary tree”. A binary tree is a type of data structure known in the art of algorithms, which arranges data hierarchically. The tree may be queried to obtain data about the variable.

One enterprise model, manufactured at one time by Optimax Corporation under the trademark OPTIFLEX, used a binary tree to represent a time varying function. At each node, certain values relative to the “subtree” of that node were stored.

SUMMARY OF THE INVENTION

One aspect of the invention is a method of storing values of a time-varying variable. The variable is represented as a time-varying function having time values and function values. The time-varying function is then represented as a balanced binary tree, each node of the tree associated with a change in value of the function. A node may store an “override” value, which represents a predetermined change in value of the function, such as a capacity value of a resource that is periodically replenished. The stored values at each node are a time value, a delta value, a maximum subtree value, and a minimum subtree value. The latter two “subtree values” are referred to as such because they represent a relative contribution from the subtree beginning with that node.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is an example of a time-varying function, to be represented with a binary tree data structure in accordance with the invention.

FIG. 2 illustrates the binary tree structure of the invention, as well as data stored at each node.

FIG. 3 illustrates an example of a particular time-varying function.

FIG. 4 illustrates a binary tree representing the function of FIG. 3.

FIG. 5 illustrates a simple query system that uses the binary tree of the present invention.

FIG. 6 illustrates a binary tree having a delta node with an override value, also referred to as an “override node”.

DETAILED DESCRIPTION

Binary Tree with Delta Nodes

FIG. 1 illustrates a time varying function, f(t), which is to be represented as a data structure in accordance with the invention. The function can be expressed as a set, S, of ordered pairs, S=(Xi, δ(Xi)) ={(t1, δ(t1)), (t2, δ(t2)) . . . (tn, δ(tn))}, such that the value of f(t) at any time T is f(T)=δ(X1)+δ(X2)+. . . .+δ(Xn) with n ≦ t. A function represented in this manner is sometimes referred to as a “fluent” function.

Expressed less formally, f(t) can be expressed as a sequence of delta (δ) values in increasing order of time. It is assumed that the initial value of F(t) is 0. It is further assumed that the values of t and δ are real values. The value of f(t) at a particular time, T, is computed by adding all the delta values that come before that time.

In practical application, f(t) might be an amount of inventory. Over time, the amount of inventory changes, giving rise to delta values, as inventory is shipped out and replenished. Throughout the operation of an ongoing enterprise, new deltas (plus or minus) are continually being added to the function. Meanwhile, queries about the amount of inventory are being made. As illustrated by the examples in the Background, there might be a need to know f(t) at a specified time t or a need to know a time at which at least a specified value of f(t) will be available, i.e., an amount ≦ Y.

FIG. 2 illustrates the binary tree structure of the present invention, as well as the data stored at each node and the functions that may be called at a node.

Each node, N, stores the following values: t(N), δ (N), Net(N), Min(N), and Max(N). Each node of the tree corresponds to a member of the set of ordered pairs described above in connection with FIG. 1. Thus, at any node, the stored values t and 6 are an ordered pair associated with f(t). The stored data are used during traversal of the tree to solve queries to the tree.

The tree is balanced, in that the root node divides the members of f(t) in half. In other words, half the members of f(t) are to the left of R and half are to the right (within a margin of one to cover the case of an even number of nodes). Thus, for example, if f(t) has n+1 members, n/2 members are to the left of the root node and n/2 members are to the right of the root node. As new deltas occur and f(t) acquires new members, new nodes are added. The tree is re-balanced when appropriate, which causes the values stored in the root node to change. A special case is when the new node has a value of t that is the same as an existing node, in which case the values stored in the node are updated.

Each node has an associated time span that is determined by its position in the tree. The root of the tree, at node R, corresponds to the entire time span of f(t), i.e., the “root time span”, which is from −∞ to +∞. Thus, for the root node, −∞>t<+∞. The root node partitions this time span into two parts, one associated with the subtree to the left of R and one associated with the subtree to the right of R. Likewise, each node under the root node partitions its associated time span into two parts. Thus, going down the tree, the nodes′ subtrees represent smaller subdivisions of the root time span. Leaf nodes, such as nodes L4 and R4, have no subtree.

As stated above, each node N stores the following associated values:

t(N)=time at which a delta occurs

δ(N)=value of delta at t

Net(N)=sum of deltas in the subtree

Max(N)=maximum cumulative change in the subtree

Min(N)=minimum cumulative change in the subtree

The latter three values are calculated from values of members of node N's subtree.

Net(N), defined above as the sum of deltas in the subtree (which includes the delta of the node itself), can be calculated as the difference between the function value immediately after the last delta in the subtree and the function value immediately before the first delta. In other words, the net value is determined from a “start value”, S(N), and “end value”, E(N), associated with the subtree of any node, N. The “start value” for a node is the value of f(t) immediately before the earliest (left-most) delta in the node's subtree. The “end value” is the value immediately after the last (right most) delta in the node's subtree. The end value is also the start value plus the net value, or E(N)=S(N)+Net(N).

For the root node, the start value is zero, or S(N)= 0. At all times after the last delta, the value of f(t) is the net value of the root, Net(R). This is because at the root, the end value is the same as the last value and the start value is zero. For a leaf node, the net value is the same as the delta value, or Net(N)=δ(N).

The start value and end values, S(N) and E(N), are not stored. However, as the tree is traversed from the root node to a leaf node, S(N) can be calculated at each node. If N is a parent node, and L and R are its left and right children, then S(L) =S(N) because they have the same leftmost delta. The value of S(R) can be can determined from known and stored values: S(R)=S(N)+Net(L)+δ(N).

Min(N) is the lowest function value relative to S(N) achieved at any point in the node's subtree. In other words, the lowest function value reached in the time interval associated with a node N is S(N)+Min(N). Min(N) does not represent a “weak” lower bound—the value of f(t) is guaranteed to reach S(N)+Min(N) in the time interval. Max(N) is like Min(N), except that it is the highest function value relative to S(N).

If the node is a leaf node, Min(N) is the minimum of zero and δ(N). This is because if δ(N) is positive, the lowest value is S(N), which is the value before t(N). Similarly, for a leaf node, Max(N) is the maximum of zero and δ(N).

For any non-leaf node N, with left and right children L and R:

Net(N)=Net(L)+Net(R)+δ(N)

Min(N)=minimum of Min(L) and (Net(L)+δ(N)+Min(R))

Max(N)=maximum of Max(L) and (Net(L)+δ(N)+Max(R))

The calculation of Min(N) can be explained as follows. As stated above, S(N)=S(L) and S(R) =S(L)+Net(L)+δ(N). Because Min(R) is relative to S(R) but Min(N) is relative to S(N), it is adjusted by S(R)−S(N) to determine whether the minimum value reached under R is the minimum value reached under N. S(R)−S(N)=Net(L) +δ(N). Thus, the calculation of Min(N) considers the minimum value reached under each child's subtree, with the right-hand subtree minimum adjusted for the difference in start values.

As is evident from the above discussion, the data stored in a node is local to that node's subtree. The data does not depend on values before or after the time interval associated with the subtree. Each node stores at least one “subtree value” (Net(N), Min(N), or Max(N)), each of which represents a relative contribution of the subtree to a function value.

As explained below, when the tree is traversed for solving a query, these subtree values are used to calculate absolute values from which function values are determined. More specifically, the Net(N) subtree value is the basis for calculating the function value at that node. The Min(N) and Max(N) subtree values are the basis for calculating maximum and minimum bounds of function values within the subtree.

Operations on Binary Tree with Delta Nodes

An Insert Delta operation is used to insert a new delta. For example, suppose a delta at time t with value δ(t) is to be inserted. The tree is traversed downwardly, looking for the leaf node under which the node must be inserted in order to preserve the time-ordering relation in the tree. The new node is inserted it as a leaf node under the previous leaf node. Because this new node is a leaf node, its Net, Min, and Max can be calculated. Then, the “update” operation is performed. This operation can be performed in time O(log n) in a height-balanced tree with n delta nodes.

A Change Delta operation is similar to the Insert Delta operation. The tree is traversed downwardly from the root node until arriving at the node to be changed. Its value is changed, and an Update Delta operation is performed. This operation is also performed in time O(log n) with n delta nodes inserted in a height-balanced tree.

An Update Delta operation deals with the effect of a change in the delta of a node. First, the time of the changed delta is tested against the root node. If the changed delta is to the left (in the left sub-tree), then the descendent nodes to the right of the root node do not need to be changed. This is because the stored values for each node are local to each tree branch. As the only branch that was changed was the left one, the right branch and all the corresponding nodes remain unchanged.

The same applies if the node being changed is located in the right sub-tree.

The root node itself will have its Net, Min, and Max values updated. Going down the tree, the visited nodes are marked until the node being changed is reached.

These are the only nodes that need to be updated, because they correspond to time intervals containing the node being updated. This operation can be performed in time O(log n) in a height-balanced tree with n delta nodes.

A Calculate Function Value operation, explained by example in connection with FIGS. 3 and 4, returns the function value at a given time point. The tree is traversed to the node, N, immediately before the time in question. The function value is S(N)−Net(L)+δ(N), where L is the left child of N. The complexity is O(log n) with n nodes in a height-balanced tree.

Various Find operations include Find Earliest, Find latest, Find Maximum, and Find Minimum.

The Find Earliest operation, explained by example in connection with FIGS. 3 and 4, returns the earliest time, t, when the function value is less, less or equal, greater, greater or equal than a specified value, y. At each node, its left child is visited first, then the right child, thus the nodes with earlier times are visited first. At each node, this operation makes use of the Max and Min values and the bounding box explained above. Because the bounding box sometimes provides a “maybe” rather than a certainty, both the left and right nodes must sometimes be searched. Nevertheless, the search complexity is 0(log n) in a height-balanced tree with n nodes.

A Find Latest operation is similar to the Find Earliest operation, with the difference that right children are visited first, because the query is for the latest time point that satisfies the search criteria. The search complexity is the same.

The Find Maximum and Find Minimum operations find the maximum or minimum function value over a specified time interval. Like the other Find operations, these operations use the Max and Min fields at each node and can be performed in O(log n) time.

Example of f(t) with Delta Nodes

FIG. 3 illustrates an example of a function, f(t), defined by six pairs of (t, δt) values. Each t value has a corresponding δ value and a corresponding function value (after δ). Prior to the first δ value at t=1, the function value is zero, or f(t)=0. Thus, the function value is zero from negative infinity to t=1.

After the last δ, the function holds the final value, thus f(t)=3 from t=7 to positive infinity. At any particular time, t, there is a function value just prior to t and a function value just after. There may or may not be a δ at any given time point—the deltas may remain constant during some time increments.

FIG. 4 illustrates a binary tree built from the function of FIG. 3. Each node is illustrated with its stored node values, t(N), δ(N), Net(N), Min(N), and Max(N). For purposes of explanation, a calculated start value, S(N), associated with the node's subtree is also shown.

To perform the Calculate Function Value operation, the function value f(t) any time is calculated from the stored values, Net(N) and δ(N), and the calculated start value, S(N). To find the function value at time, t, the node, N, is found with the time closest to but not greater than t. As the tree is descended to the time in question, S(N) is calculated at each node. The function value at t is expressed as: f(t)=S(N)+Net(L)+δ(N), where L is the left child of N. If N has no left child, then Net(L) is defined to be zero.

Referring to the example of FIGS. 3 and 4, to find the function value at t=δ, the tree is traversed to node B, calculating S(N) for each visited node. Starting at the root node, by definition S(Root)=0. Descending to node B, because B is a right child of the root node, S(5)=S(Root)+Net(A)+δ(Root) as explained above in connection with FIG. 2. By substitution, S(B)=0 +4+(−3)=1. Expressed less formally, S(B) is the function value prior to the subtree under B, i.e., the function value just before node B at t=5. For the function value at node B, t=6, thus f(t=6)=S(B)+Net(D)+δ(B)=1+(−3)+7=5.

For variations of this example, if the tree were to be descended from node B to node D, because D is a left child, then S(D)=S(B)=1. To find the function value at t=5.5, the tree would be traversed to node D. At D, f(t=5.5)=S(D)+0+δ(D)=1+(−3)=−2.

The Max and Min values are used to perform the various Find operations. Find operations are directed to finding the earliest/latest time at which f(t) is greater/less than y, or to finding the maximum/minimum value during a specified time interval.

In general, the Max and Min values permit earliest/latest queries to handle <, >, ≦, and ≧ predicates. The key to doing this efficiently is that at every node, there is a “bounding box” defined by the time interval covered by the node's subtree and by the minimum and maximum function values that occur within that node (relative to the start value for the node). If the start value of a node N is S(N), then somewhere within the time interval for the node, there is a maximum value of S(N)+Max(N) and a minimum value of S(N)+Min(N). (The maximum or minimum might be S(N) itself.) As the tree is traversed from the root toward the leaves, S(N) for each node is calculated as well as the minimum and maximum function values reached within that node's subtree.

The bounding box often guarantees whether a time satisfying the find query is or is not within a subtree.

However, in some cases, the bounding box can provide only a “maybe”. Using the example of FIGS. 3 and 4, a “maybe” situation would occur when the query is “find a time greater than t=4 when f(t)>2”. At the root node, its bounding box indicates that the function value reaches 2 sometime between t=0 and t=7, but does not indicate whether this occurs before or after t>4. However, a feature of the invention is the likelihood that a node's bounding box will indicate either “yes” or “no” that the solution is in that node's subtree.

Referring to the example of FIGS. 3 and 4, a Find query might ask for the earliest time after t=4 at which the function value is >2. The bounding box for the root node includes times from t=1 to t=7, and function values from a minimum of −2 to a maximum of +6. (If the query were for the earliest time at which the function value is >10, the query would end, because the solution is outside the bounding box.) Because t=4 is greater than t(Root)=3, the solution is in the right subtree. At node B, the bounding box includes times from t=5 to t=7. The start value for the subtree at B, S(B), is calculated to be 1, so the function values for the bounding box at B have a lower bound of −2 and an upper bound of 5. (S(N)+Min and Max, respectively). Somewhere within the bounding box there is a t>4 where the function value is greater than 2. The search continues in this fashion, working down the tree, checking the bounding boxes at each point.

Typically, both the Min and Max fields will be stored so that both “earliest” and “latest” find queries can be solved. However, the invention would be useful with only one of these queries available. In this case,

as the tree is traversed, only one bound of the function values within the subtree would be calculated.

Ouery System for Using the Binary Tree

FIG. 5 illustrates a simple query system 50 for using a binary tree having the above-described structure.

As indicated above, the system 50 may be part of a comprehensive model and query system used for scheduling and/or planning. For example, system 50 might be part of a supply chain planning system.

The various elements of system 50 are implemented on a computer, using known processing, memory, and I/O devices.

A user inputs a query, such as one of the various queries described above, via a user interface 51. The query is provided to a query engine 52, which stores and executes various algorithms that accomplish tree searching and related calculations. During operation, engine 52 accesses the appropriate binary tree 52, stored in memory. Binary tree 53 may be part of a larger model, such as the model 12 described above.

Binary Tree with Override Nodes

Sometimes it is useful to model a resource whose capacity is replenished periodically, with unused capacity lost at the end of each period. For example, assume a bucketized scheduling model having a bucket size of one week. If a certain machine can handle one hundred units of production in a week, then that resource can be modeled as having a capacity that is reset to one hundred at the beginning of each week. If only fifty units are produced during a week, the unused capacity does not carry over into the next week.

An override function can be modeled with a binary tree similar to that described above for resources having delta values. However, the binary tree will have nodes with “override” values. The override values may occur, but need not occur, at periodic intervals.

In a general sense, nodes having override values are “delta” nodes but the delta values for those nodes are predetermined. For purposes of description, the two types of nodes can be distinguished by referring to them as “delta” nodes and “override” nodes. The binary tree may be entirely comprised of override nodes, or it may have both override nodes and delta nodes.

FIG. 6 illustrates time-varying function, from which a binary tree having both override nodes (ONs) and delta nodes (DNs) may be generated. The delta nodes are the same as those described above in connection with FIGS. 1-4. In the example of FIG. 6, the override nodes are at periodic intervals, every 8 units of time, and cause the function value to override to a value of 6.

For example, a resource capacity might replenish to 6 units every 8 days.

Each override node stores a time and an override value, and may also have any or all of the Net, Max, and Min values described above. The function value at an override node is the value of the override node at the time of the override node, independent of any previously occurring overrides or deltas.

When a tree is constructed of both override nodes and delta nodes, no override node has a delta node as a parent. The child of an override node can be an override node or a delta node.

Thus, an override node can have a subtree of delta nodes under it. This subtree would represent deltas after the time of the override and before the time of the next override. It is not possible to have both an override and a delta at the same time.

The initial function value can be set by having an override node at −∞. Alternatively, the initial function value can be at a time determined to be the earliest possible time for the tree.

Operations on Trees with Override Nodes

The operations described above for trees with only delta nodes can be modified for application to trees with override nodes.

For Find operations (find earliest and find latest), the bounding box calculation is modified. Specifically, when an override node is visited, the effect of deltas prior to that node is ignored. Otherwise, the algorithm is the same.

The Insert Delta operation is modified, such that when a delta is inserted into the tree, the next override node after the time of the delta is located and the bounding box data at that override node is adjusted.

The Change Delta operation is also modified so that the data stored at the next override node is adjusted.

The Insert Override operation recognizes that an override node may have a tree of delta nodes under it. If an override node is inserted at time t, the tree of deltas under the previous override is split. All deltas after time t are placed under the new override node.

The Change Override operation is similar to the operations for changing or inserting a delta node. The data stored at the next override node is adjusted.

The Delete Delta operation is unchanged.

The Delete Override operation requires the deltas under the deleted override to be merged into the tree of deltas under the previous override node.

Other Embodiments

Although the present invention has been described in detail, it should be understood that various changes, substitutions, and alterations can be made hereto without departing from the spirit and scope of the invention as defined by the appended claims. 

What is claimed is:
 1. A method of storing values of a time-varying variable, comprising the steps of: representing the variable as a time-varying function having time values and function values; creating a balanced binary tree, each node of the tree associated with a change in value of the function; and for each node, storing a time value, a delta value, a maximum subtree value, and a minimum subtree value, each subtree value representing a relative contribution from the subtree beginning with that node; wherein at least one node is an override node, such that its delta value is a predetermined override value.
 2. The method of claim 1, wherein the function is a step function and each node stores a constant delta value.
 3. The method of claim 1, wherein said storing step is further performed by storing, for each node, a net subtree value representing the sum of deltas in the subtree associated with that node.
 4. A method of solving find earliest/latest queries about values of a time-varying function, comprising the steps of: representing the function as a balanced binary tree, the tree having delta nodes that each represent a change in value of the variable, each node having an associated time value, delta value, subtree maximum value, and subtree minimum value; wherein at least one nodes stores a delta value that is a predetermined override value; traversing the tree, at each node calculating function bounding values representing the maximum and minimum function values associated with the subtree and a start value representing the function value at the start of the time span associated with the subtree; and at each node, using the associated function bounding values and start value to determine if the solution is in the subtree of that node.
 5. The method of claim 4, wherein the query specifies an upper bound on quantity, and the traversing step solves the query by finding an earliest time when the quantity satisfies that bound.
 6. The method of claim 4, wherein the query specifies an upper bound on quantity, and the traversing step solves the query by finding a latest time when the quantity satisfies that bound.
 7. The method of claim 4, wherein the query specifies a lower bound of quantity, and the traversing step solves the query by finding an earliest time when the quantity satisfies that bound.
 8. The method of claim 4, wherein the query specifies a lower bound of quantity, and the traversing step solves the query by finding a latest time when the quantity satisfies that bound.
 9. The method of claim 4, wherein the query specifies a lower bound on time and a lower bound on quantity, and the traversing step solves the query by determining the earliest time after the specified time bound when the quantity satisfies the specified quantity bound.
 10. The method of claim 4, wherein the query specifies an upper bound on time and a lower bound on quantity, and the traversing step solves the query by determining the latest time before the specified time bound when the quantity satisfies the specified quantity bound.
 11. The method of claim 4, wherein the query specifies a lower bound on time and an upper bound on quantity, and the traversing step solves the query by determining the earliest time after the specified time bound when the quantity satisfies the specified quantity bound.
 12. The method of claim 4, wherein the query specifies an upper bound on time and an upper bound on quantity, and the traversing step solves the query by determining the latest time before the specified time bound when the quantity satisfies the specified quantity bound.
 13. The method of claim 4, wherein the query specifies a time interval, and the traversing step solves the query by determining a maximum in the time interval.
 14. The method of claim 4, wherein the query specifies a time interval, and the traversing step solves the query by determining a minimum in the time interval.
 15. A computer-readable medium for storing programming operable to provide values of a time-varying variable, by performing the steps of: representing the variable in terms of a function that is a series of time value and function value pairs; creating a balanced binary tree, each node of the tree having an associated time value and delta value representing a change in value of the function, wherein at least one delta value is a predetermined override value; accessing the tree in response to a query; and using delta values obtained during the accessing step to determine at least one function value that represents the value of the variable at a certain time.
 16. A system for providing on-hand inventory data, comprising: a memory that stores a balanced binary tree that representing inventory values in terms of a function that is a series of time value and function value pairs; wherein each node of the tree has an associated time value and delta value representing a change in value of the function, and each node stores either a producer delta or a consumer delta, with each producer delta having a positive value and each consumer delta having a negative value; and an engine for accessing the tree, the engine further operable to use delta values to determine at least one value of the function that represents inventory quantity at a certain time.
 17. The system of claim 16, further comprising a user interface operable deliver query data to the engine, and to provide data output derived from the function value, in response to the query. 